package com.fenghuajueli.idiomppp.ui.fragment.yuyanstory;


import android.content.Intent;
import android.os.Bundle;

import android.widget.GridView;

import com.fenghuajueli.idiomppp.R;
import com.fenghuajueli.idiomppp.adapter.AllIdiomGridAdapter;
import com.fenghuajueli.idiomppp.config.BizCallBack;
import com.fenghuajueli.idiomppp.entity.VideoInfoEntity;
import com.fenghuajueli.idiomppp.ui.fragment.allidiom.AllStoryPresenter;
import com.fenghuajueli.idiomppp.ui.fragment.allidiom.AllStoryView;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;
import com.fenghuajueli.libbasecoreui.mvp.LifecycleBaseFragment;


import java.util.List;

/**
 * 寓言故事列表
 */
public class YuYanStoryFragment extends LifecycleBaseFragment<AllStoryPresenter> implements AllStoryView {

    GridView idiomGridView;
    AllIdiomGridAdapter allIdiomGridAdapter;

    public static BizCallBack mBiz;

    @Override
    public AllStoryPresenter initPresenter() {
        return new AllStoryPresenter(getActivity());
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        idiomGridView = (GridView) findViewById(R.id.idiomGridView);

    }

    @Override
    protected void firstLoadData() {
        presenter.loadYuYanData();
    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_yu_yan_story;
    }

    public static YuYanStoryFragment newInstance() {

        Bundle args = new Bundle();

        YuYanStoryFragment fragment = new YuYanStoryFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void dataLoadSuccess(List<VideoInfoEntity> videoInfoEntities) {
        allIdiomGridAdapter = new AllIdiomGridAdapter(getActivity(), videoInfoEntities);
        allIdiomGridAdapter.setOnListClickListener(new OnListClickListener<VideoInfoEntity>() {
            @Override
            public void itemClick(int position, VideoInfoEntity data) {

                if(mBiz!=null){
                    if(mBiz.onBiz(position)){
                        //跳视频

                    }
                }else {
                    //跳视频

                }
            }
        });
        idiomGridView.setAdapter(allIdiomGridAdapter);
    }
}
